<?php 

namespace Admin\Model ; 
use Think\Model ; 
class GoodsModel extends Model {


     protected $_validate = array(
        array('goods_name','require','商品名称必须填写！',1 ,'',3),      
        array('cat_id','0','商品分类必须填写。',1,'notequal',3),
        array('goods_sn','','商品货号重复！',2,'unique',1),        
        array('shop_price','/\d{1,10}(\.\d{1,2})?$/','本店售价格式不对。',2,'regex'),   
        array('store_count','/\d{1,}?$/','库存数量不正确',2,'regex'), 
        array('sort','/\d{1,}?$/','排序不正确',2,'regex'),   
        array('give_integral','/\d{1,}?$/','赠送积分不正确',2,'regex'),        
     );  

	protected $_auto = array ( 
			array('goods_sn','get_goods_sn' , '1' , 'function'), 
			array('click_count','0','1'),
			array('comment_count','0'),
			array('last_update','time','1','function'),
			array('prom_id','0'),       
		);

    function getClassByPids($arr){
        if(empty($arr)){
            return ;
        }
        $return = array();
        foreach($arr as $k => $v){
            $tmp = $this->where('cat_id=' . $v['id'])->select();
            $return [] = $tmp ;
        }

        return $return ; 
    }

}